package cn.kgc.springcloud.controller;

import cn.kgc.springcloud.service.HelloService;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author 课工场
 * @date 2024/5/7
 * @description
 */
@RestController
@RequestMapping("hello")
public class HelloController {

    @Resource
    private HelloService helloService;

    @GetMapping("m1")
    public String  method1(){
        String s = helloService.method3();
        return "HelloController method1 ok >> HelloService >>"+s;
    }

    @GetMapping("m2")
    public String  method2(){
        String s = helloService.method3();
        return "HelloController method2 ok  >> HelloService >> "+s;
    }


    @GetMapping("m4")
    public String  method4(){
        System.out.println(System.currentTimeMillis()+"  请求在队列中排队执行.....");
        return "HelloController method2 ok  >> HelloService >> ";
    }


    @GetMapping("m5")
    public String  method5(Integer id){

        if (id<0){
            throw  new RuntimeException("参数异常");
        }

        return "HelloController method2 ok  >> HelloService >> ";
    }


    @ExceptionHandler(RuntimeException.class)
    public String  method5Callback(Exception e){

        return "服务参数异常";
    }

}
